package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by lirong
 * date : 2017/6/10
 * time : 19:10
 */
public class DBHelper {

    private static final String driver ="com.mysql.jdbc.Driver";

//    private static final String url="jdbc:mysql://58.63.39.168:13306/javaTest?useUnicode=true&characterEncoding=UTF-8";
    private static final String url="jdbc:mysql://58.63.39.168:13306/javaTest";
    private static final String usename="root";
    private static final String password="sql@8234ERe8";

    private static Connection conn =null;

    static {
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {

        if (conn==null){
            conn = DriverManager.getConnection(url,usename,password);
            return conn;
        }
        return conn;
    }

    public static void main(String[] args) {
        try {
            Connection conn =DBHelper.getConnection();
            if (conn!=null){
                System.out.println("数据库链接正常!");
            }else {
                System.out.println("数据库链接移除!");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }



}
